#include "EventEngine.h"
#include "IGameEvent.h"
#include "IConnection.h"

using namespace ENE;

EventEngine::EventEngine(ChuGame::GameState& state, IConnection& connection) : m_state(state), m_connection(connection)
{

}

void EventEngine::handleEvent(boost::shared_ptr<const IGameEvent> event)
{
	m_connection.sendEvent(event);
}

void EventEngine::pushEvent(boost::shared_ptr<const IGameEvent> event)
{
	//Lock la queue d'events
	boost::mutex::scoped_lock lock(m_evMutex);
	//Ajoute l'event a la queue
	m_events.push(event);
}

void EventEngine::update(float elapsedTime)
{
	//Lock la queue d'events
	boost::mutex::scoped_lock lock(m_evMutex);
	//Traite et vide la queue d'event
	while(!m_events.empty())
	{
		m_state.applyEvent(m_events.front());
		m_events.pop();
	}
}

